import { 
    fetchAccLists, 
    fetchSaveAccInfo, 
    fetchSaveModifyPass, 
    fetchSetAccState, 
    fetchCitysLists,
    fetchSearchCityByName
} from '../../fetch/modules/addSubAcc'

const state = {
    accLists: {},
    savedAccInfo: {},
    savePass: {},
    setAccStateInfo:{},
    citysLists: {},
    searchCityInfo: {}
}

const actions = {
    FETCH_ACC_LISTS: ({ commit, state }) => {
        return fetchAccLists().then(acc => commit('GET_SUB_ACC_LISTS', { acc }))
    },
    FETCH_ADD_ACCINFO: ({ commit, state }, opts) => {
        return fetchSaveAccInfo(opts).then(acc => commit('SAVE_ACC_INFO', { acc }))
    },
    SAVE_MODIFY_PASS: ({ commit, state }, opts) => {
        return fetchSaveModifyPass(opts).then(acc => commit('FETCH_SAVE_PASS_INFO', { acc }))
    },
    SET_ACC_STATE: ({ commit, state }, opts) => {
        return fetchSetAccState(opts).then(acc => commit('FETCH_SET_ACC_STATUS', { acc }))
    },
    GET_ALL_CITY_DATA: ({ commit, state }, opts) => {
        return fetchCitysLists(opts).then(acc => commit('GET_CITY_DATAS', { acc }))
    },
    GET_SEARCH_CITY_DATA: ({ commit, state }, opts) => {
        return fetchSearchCityByName(opts).then(acc => commit('FETCH_SEARCH_CITY', { acc }))
    }
}
const mutations = {
    GET_SUB_ACC_LISTS: (state, { acc }) => {
        state.accLists = acc.data;
    },
    SAVE_ACC_INFO: (state, { acc }) => {
        state.savedAccInfo = acc.data;
    },
    FETCH_SAVE_PASS_INFO: (state, { acc }) => {
        state.savePass = acc.data;
    },
    FETCH_SET_ACC_STATUS: (state, { acc }) => {
        state.setAccStateInfo = acc.data;
    },
    GET_CITY_DATAS: (state, { acc }) => {
        state.citysLists = acc.data;
    },
    FETCH_SEARCH_CITY: (state, { acc }) => {
        state.searchCityInfo = acc.data;
    },

}
const getters = {
    getSubAccLists(state) {
        return state.accLists
    },
    saveSubAccInfo(state) {
        return state.savedAccInfo
    },
    saveModifyPassInfo(state) {
        return state.savePass
    },
    setAccStateInfo(state) {
        return state.setAccStateInfo
    },
    allCityData(state) {
        return state.citysLists
    },
    searchCity(state) {
        return state.searchCityInfo
    }
}

export default {
    state,
    actions,
    mutations,
    getters
}